#! /usr/bin/python
# ftp_birdlist.py

"""This mudule uploads a birdlist to the internet

The user needs to supply the log in details and the file to be uploaded
if the module is to be used on its own

"""

import ftplib
import os

class UploadBirdlist:
    """Upload a birdlist to the given website directory"""
    def __init__(self, fullpath, host, hostDir, usr, psw):
        self.fullpath = fullpath
        self.filename = os.path.split(fullpath)[1]
        self.host = host
        self.host_dir = hostDir
        self.usr = usr
        self.psw = psw
    def ftp_upload(self):
        """Uploader"""
        try:
            ftp = ftplib.FTP(self.host)
            ftp.login(self.usr, self.psw)
            ftp.cwd(self.host_dir)
            f = open(self.fullpath,'rb')
            ftp.storbinary('STOR ' + self.filename, f)
            f.close()
            ftp.quit()
            did_ = 1
        except:
            did_ = 0
        return did_
    
if __name__ == "__main__":
    #write test parameters
    pass